package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizPatient;
import com.ambulance.project.manager.service.IBizPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 病员急救信息Controller
 *
 * @author zr
 * @date 2020-05-11
 */
@RestController
@RequestMapping("/manager/patient")
public class BizPatientController extends BaseController {
    @Autowired
    private IBizPatientService bizPatientService;

    /**
     * 查询病员急救信息列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPatient bizPatient) {
        startPage();
        List<BizPatient> list = bizPatientService.selectBizPatientList(bizPatient);
        return getDataTable(list);
    }

    /**
     * 导出病员急救信息列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:patient:export')")
    @Log(title = "病员急救信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizPatient bizPatient) {
        List<BizPatient> list = bizPatientService.selectBizPatientList(bizPatient);
        ExcelUtil<BizPatient> util = new ExcelUtil<BizPatient>(BizPatient.class);
        return util.exportExcel(list, "patient");
    }

    /**
     * 获取病员急救信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:patient:query')")
    @GetMapping(value = "/{patientId}")
    public AjaxResult getInfo(@PathVariable("patientId") Long patientId) {
        return AjaxResult.success(bizPatientService.selectBizPatientById(patientId));
    }

    /**
     * 新增病员急救信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:patient:add')")
    @Log(title = "病员急救信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPatient bizPatient) {
        return toAjax(bizPatientService.insertBizPatient(bizPatient));
    }

    /**
     * 修改病员急救信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:patient:edit')")
    @Log(title = "病员急救信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPatient bizPatient) {
        return toAjax(bizPatientService.updateBizPatient(bizPatient));
    }

    /**
     * 删除病员急救信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:patient:remove')")
    @Log(title = "病员急救信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{patientIds}")
    public AjaxResult remove(@PathVariable Long[] patientIds) {
        return toAjax(bizPatientService.deleteBizPatientByIds(patientIds));
    }
}
